package com.mall4j.cloud.api.coupon.feign;

import com.mall4j.cloud.api.coupon.bo.CouponBO;
import com.mall4j.cloud.api.coupon.dto.CouponAllocateReq;
import com.mall4j.cloud.api.coupon.dto.CouponUseReq;
import com.mall4j.cloud.api.coupon.dto.CouponUseResultDto;
import com.mall4j.cloud.api.coupon.dto.UpdateCouponOrderReq;
import com.mall4j.cloud.common.feign.FeignInsideAuthConfig;
import com.mall4j.cloud.common.order.vo.ShopCartOrderMergerVO;
import com.mall4j.cloud.common.response.ServerResponseEntity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@FeignClient(value = "mall4cloud-coupon",contextId ="coupon")
public interface CouponFeignClient {
    // 获取用户的优惠卷
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX+"/insider/getUserCoupon")
    List<CouponBO> getUserCoupon(@RequestParam("userId") Long userId);

    // 使用优惠卷，返回使用结果，不会操作数据库
    @PostMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX+"/insider/useCoupon")
    ServerResponseEntity<CouponUseResultDto> useCoupon(@RequestBody CouponUseReq couponUseReq);
    // 更新优惠卷状态成已使用，和设置优惠卷在当前订单的价值
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX+"/insider/updateCouponTOUse")
    ServerResponseEntity<Integer> updateCouponToUse(@RequestBody UpdateCouponOrderReq updateCouponOrderReq);
    // 通过订单id获取优惠卷的价值
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX+"/insider/getCouponValueByOrderId")
    ServerResponseEntity<Long> getCouponValueByOrderId(@RequestParam("orderId") String orderId);
    // 分配优惠卷到用户
    @PostMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX+"/insider/allocateCoupon")
    ServerResponseEntity<Void> allocateCoupon(@RequestBody CouponAllocateReq allocateReq);
}
